import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  ParseIntPipe,
  Post,
  Put,
  Query,
  Request,
  UseGuards,
} from '@nestjs/common'
import { ApiQuery, ApiTags } from '@nestjs/swagger'
import { GenerateQuery } from '../../common/interfaces/basetype.interface'
import { ResponseData } from '../../common/interfaces/result.interface'
import { RoleDct } from '../../decorators/role.dct.decorator'
import { JwtAuthGuard } from '../user/guards/jwt-auth.guard'
import { RoleGuard } from '../user/guards/role.guard'
import { UserRoles } from '../user/user.entity'
import { CreateRoleDto } from './dto/create-role.dto'
import { UpdateRoleDto } from './dto/update-role.dto'
import { RoleService } from './role.service'

@Controller('role')
@ApiTags('角色控制')
// @UseGuards(JwtAuthGuard, RoleGuard)
// @RoleDct(UserRoles.admin, UserRoles.super)
export class RoleController {
  constructor(private readonly roleService: RoleService) {}

  @Get(':id')
  async findOne(@Param('id', ParseIntPipe) id: number): Promise<ResponseData> {
    return await this.roleService.findOne(id)
  }

  @Get()
  @ApiQuery({ name: 'name', required: false })
  @ApiQuery({ name: 'title', required: false })
  async findAll(@Query() query: GenerateQuery): Promise<ResponseData> {
    return await this.roleService.findAll(query)
  }

  @Post()
  async create(@Body() body: CreateRoleDto): Promise<ResponseData> {
    return await this.roleService.create(body)
  }

  @Put(':id')
  async update(
    @Param('id', ParseIntPipe) id: number,
    @Body() body: UpdateRoleDto,
  ): Promise<ResponseData> {
    return await this.roleService.update(id, body)
  }

  @Delete(':id')
  async remove(@Param('id', ParseIntPipe) id: number): Promise<ResponseData> {
    return await this.roleService.delete(id)
  }
}
